<template>
  <div v-loading.fullscreen.lock="loading"></div>
  <el-breadcrumb separator="/" class="mb-2 mt-1" style="vertical-align: bottom">
    <el-breadcrumb-item>
      <div class="flex align-center">
        <el-icon :size="18"> <User /> </el-icon><span class="pl">顧客管理</span>
      </div>
    </el-breadcrumb-item>
    <el-breadcrumb-item>顧客分組</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card class="box-card" shadow="hover">
    <template #header>
      <div class="flex justify-end flex-wrap">
        <el-space wrap :size="10">
          <el-button type="primary" plain>增加</el-button>
          <el-button type="primary" plain>下載</el-button>
          <el-button type="primary" plain>模版下載</el-button>
          <el-button type="primary" plain>導入分組</el-button>
        </el-space>
      </div>
    </template>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="group_id" label="ID" />
      <el-table-column prop="group_name" label="分组名称" />
      <el-table-column prop="group_num" label="分组人数" />
      <el-table-column prop="create_time" label="创建时间" />
      <el-table-column fixed="right" label="操作" width="200">
        <template #default="scope">
          <el-space wrap :size="5">
            <el-button
              link
              size="small"
              type="primary"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              link
              size="small"
              type="danger"
              @click="handleEdit(scope.$index, scope.row)"
              >删除</el-button
            >
            <el-button
              v-if="scope.row.group !== ''"
              link
              size="small"
              type="info"
              @click="handleDelete(scope.$index, scope.row)"
              >分组用户</el-button
            >
            <el-button
              link
              size="small"
              type="warning"
              @click="handleDelete(scope.$index, scope.row)"
              >下载</el-button
            >
          </el-space>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="total > params.page_size" class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[20, 40, 60]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </el-card>
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { Search, User } from "@element-plus/icons-vue";
import { $groupList } from "@api/user";
let params = ref({
  current_page: 1,
  page_size: 10,
});
const filter = ref({
  group: [],
  usertype: [],
});
const content = ref("");
const loading = ref(false);
const total = ref(0);
const tableData = ref([]);
onMounted(() => {
  getData();
});

const getData = async () => {
  loading.value = true;
  let res = await $groupList(params.value);
  console.log(res);
  loading.value = false;
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const search = () => {
  console.log(params.value);
  getData();
};
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(params);
  getData();
};
</script>

<style lang="scss" scoped></style>
